var app = getApp()
Page({
    data: {
        dates: [],
        dates_index: 0,
        f_works: [],
        f_works_index: 0,
        s_works: [],
        s_works_index: 0,
        outName: [],
        outName_index: 0,
        mod_id: '',
        mod_name: ''
    },
    jump: function () {

        wx.navigateTo({
            url: '/pages/meeting/meeting',
        })
    },
    bindBusMod() {
        wx.navigateTo({
            url: '/pages/busmod/busmod',
        })
    },
    onLoad: function () {

    },
    onShow: function () {
        var mod = wx.getStorageSync('mod')
        var arrmod = mod.split('-')
        
        this.setData({
            mod_id: arrmod[0],
            mod_name: mod
        })
        // console.log(modName)
    },
    onReady: function () {
        this.getDates()
        this.getFirstWork()
        this.getOutName()
    },
    f_work_change(e) {
        this.setData({
            f_works_index: e.detail.value
        })
        this.getSecondWork(this.data.f_works[e.detail.value].key)
    },
    s_work_change(e) {
        this.setData({
            s_works_index: e.detail.value
        })
    },
    outName_change(e) {
        this.setData({
            outName_index: e.detail.value
        })
    },
    formSubmit(e) {
        // console.log('form发生了submit事件，携带数据为：', e.detail.value)
        wx.showModal({
            title: '提示',
            content: '是否提交日报',
            success(res) {
                if (res.confirm) {
                    app.postData("/business/daily_per/add2", e.detail.value).then(res => {
                        wx.showModal({
                            title: '提示',
                            content: res.data.msg,
                            success(res) {

                            }
                        })
                    });
                } else if (res.cancel) {
                    console.log('用户点击取消')
                }
            }
        })
    },
    getDates() {
        var _dates = []
        var date = new Date();
        const year = date.getFullYear();
        const month = date.getMonth() + 1;
        var day = date.getDate();
        const week = date.getDay()
        var _date = [year, this.formatNumber(month), this.formatNumber(day)].join('-')
        _dates.push(_date)
        day = day - 1;
        _date = [year, this.formatNumber(month), this.formatNumber(day)].join('-')
        _dates.push(_date)
        day = day - 1;
        _date = [year, this.formatNumber(month), this.formatNumber(day)].join('-')
        _dates.push(_date)
        if (week == 2) {
            day = day - 1;
            _date = [year, this.formatNumber(month), this.formatNumber(day)].join('-')
            _dates.push(_date)
        }
        this.setData({
            dates: _dates
        })
    },
    formatNumber(n) {
        var s = n.toString()
        return s[1] ? s : '0' + s
    },
    getFirstWork() {
        this.getDictData("bus_first_work", "dict", 1)
    },
    getSecondWork(value) {
        this.getDictData(value, "dict", 2)
    },
    getOutName() {
        this.getDictData("bus_outputName", "dict", 3)
    },
    getDictData(dictType, dictRole, type) {
        var _this = this
        var param = {
            "dictType": dictType,
            "dictRole": dictRole
        }
        app.postData("/system/dict/data/getTypeRole", param).then(res => {
            var _list = []
            try {
                if (res.data.code == 0) {
                    res.data.data.forEach(element => {
                        var list = {
                            "key": element.dictValue,
                            "value": element.dictLabel
                        }
                        _list.push(list)
                    });
                    // console.log(_list)
                    if (type == 1) {
                        _this.setData({
                            f_works: _list
                        })
                    } else if (type == 2) {
                        _this.setData({
                            s_works: _list
                        })
                    } else if (type == 3) {
                        _this.setData({
                            outName: _list
                        })
                    }
                } else {
                    wx.showToast({
                        icon: 'error',
                        title: res.data.msg,
                    })
                }
            } catch (e) {
                wx.showToast({
                    icon: 'error',
                    title: '获取信息失败',
                })
            }

        })
    },
})
// 功能模块
// public static String URL_BUSMODULE = getMethod("/business/busModule/list3");

// //字典信息
// public static String URL_DICT_GETTYPEROLE = getMethod("/system/dict/data/getTypeRole");
// //日报提交
// public static String URL_DAILY_ADD = getMethod("/business/daily_per/add");